﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class LevelSwipePrioritizedFollowPosition : PrioritizedFollowPosition
{
    private BackgroundTouch backgroundTouchManager = null;

    private float holdAtPositionTime = 2.0f;    // Time in seconds to wait before downgrading priority
    private bool hasResetHoldAtPositionCounter = false;
    private float timeHeldAtPosition = 0.0f;

    public LevelSwipePrioritizedFollowPosition(BackgroundTouch backgroundTouchManager)
    {
        this.backgroundTouchManager = backgroundTouchManager;
        //Priority = PrioritizedFollowPosition.LEVEL_SWIPE;
    }

    public override void Update(float time)
    {
        if (!backgroundTouchManager.IsDraggingBackground)               // If we aren't dragging,
        {
            if (Priority != PrioritizedFollowPosition.LEVEL_NOSWIPE)    // check to see if we're already on LEVEL_NOSWIPE. If not,
            {
                if (!hasResetHoldAtPositionCounter)                     // and we haven't yet reset the timer,
                {
                    timeHeldAtPosition = 0.0f;                          // reset it,
                    hasResetHoldAtPositionCounter = true;               // and mark it as reset.
                }
                else                                                    // otherwise,
                {
                    timeHeldAtPosition += time;                         // add the update time to our timer.
                    if (timeHeldAtPosition > holdAtPositionTime)        // if we're out of time to wait,
                    {
                        Priority = PrioritizedFollowPosition.LEVEL_NOSWIPE; // downgrade to LEVEL_NOSWIPE.
                        hasResetHoldAtPositionCounter = false;              // Mark the timer as needing to be reset (likely redundant).
                    }
                }
            }
        }
        else                                                            // Else if we are dragging,
        {
            Priority = PrioritizedFollowPosition.LEVEL_SWIPE;           // Ensure that our priority is LEVEL_SWIPE.
            hasResetHoldAtPositionCounter = false;                      // Mark the timer as needing to be reset.
        }
        Position = backgroundTouchManager.CameraPosition;
    }
}
